<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<style type="text/css">
    .datatable td input {
        background: none;
        width: 100%;
        height: 35px;
        outline: none;
        border: 0px;
        padding: 4px;
    }
    .datatable td input:focus {
        background-color:#eee;
        border: 1px solid #0040D0;
        box-shadow: 0 0 5px rgba(207, 220, 0, 0.4);
        border-radius: 2px;
    }
    .center{
        text-align: center;
    }
</style>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li><a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/nurse/index')">床位列表</a></li>
            <li class="active"><a href="#">退费</a></li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="table-responsive no-border">
                    <div class="datatable-top">
                        <div class="pull-left">
                            <form class="form-inline" style="padding-bottom: 10px">
                                <label>　住院号 ：</label>
                                <input value="${patVisit.visitNo}" class="form-control" readonly="true" style="width:100px;"/>
                                <label>姓　　名 ：</label>
                                <input value="${patVisit.patVisitIndex.name}" class="form-control" readonly="true" style="width:100px;"/>
                                <label>性别 ：</label>
                                <input value="${fns:getDictLabel(patVisit.patVisitIndex.sex, "SEX_DICT", "")}" class="form-control" readonly="true" style="width:40px;"/>
                                <label>预交金额 ：</label>
                                <input value="${patVisit.prepayments}" class="form-control" readonly="true" style="width:70px;"/>
                                <label>病床号 ：</label>
                                <input value="${patVisit.bedNo}" class="form-control" readonly="true" style="width:60px;"/>
                                <label>入院日期 ：</label>
                                <input value="<fmt:formatDate value="${patVisit.admissionDate}" pattern="yyyy-MM-dd HH:mm:ss" />" class="form-control" readonly="true" style="width:145px;"/>
                                <label>所在科室 ：</label>
                                <input value="${fns:getDeptName(patVisit.deptStayed, "")}" class="form-control" readonly="true"/>
                                <label>费别 ：</label>
                                <input value="${fns:getDictLabel(patVisit.patVisitIndex.chargeType, "CHARGE_TYPE_DICT", "")}" class="form-control" readonly="true" style="width:100px;"/>
                            </form>
                            </div><div class="pull-left">
                            <form:form id="searchForm" modelAttribute="patVisit"
                                       onsubmit="return loadDivForm('mainCenterDiv','searchForm','${ctx}/nurse/nurseReturnFeeApply/returnFee');"
                                       method="post" class="form-inline">
                                <form:hidden path="patientId"/>
                                <form:hidden path="id"/>
                                <label>计费日期 ：</label>
                                <input id="billDate" name="startDate" class="form-control Wdate" maxlength="100" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"
                                       value="${date}" style="width:100px;"/>
                                <label>项目名称 ：</label>
                                <input id="itemName" name="itemName" class="form-control" value="${itemName}"/>
                                <label>退费状况 ：</label>
                                <select id="type" name="type" class="form-control" style="width: 90px">
                                    <option value="0">未退费</option>
                                    <option value="1">待确认</option>
                                    <option value="2">已退费</option>
                                </select>
                                <input id="btnSearch" class="btn btn-primary" type="submit" value="查询"/>
                                <button id="returnFee" class="btn btn-primary">申请退费</button>
                            </form:form>
                        </div>
                    </div>
                    <table id="contentTable" class="table table-bordered mg-t datatable">
                        <thead>
                        <tr>
                            <th>项目名称</th>
                            <th>项目类别</th>
                            <th>规格</th>
                            <th>单位</th>
                            <th class="returnNum">退费数量</th>
                            <th>数量</th>
                            <th>单价</th>
                            <th>计价金额</th>
                            <th>应收金额</th>
                            <th>开单科室</th>
                            <th>开单医生</th>
                            <th>执行科室</th>
                            <th>执行医生</th>
                            <th>产生日期</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${list}" var="InpBillDetail">
                            <tr id="${InpBillDetail.id}">
                                <td>${InpBillDetail.itemName}</td>
                                <td class="center">${fns:getDictLabel(InpBillDetail.itemClass,"BILL_ITEM_CLASS_DICT" ,"")}</td>
                                <td class="center">${InpBillDetail.itemSpec}</td>
                                <td class="center">${fns:getDictLabel(InpBillDetail.units,"SPEC_UNIT" ,"")}</td>
                                <td data-amount="${InpBillDetail.amount}" class="returnNum" style="padding:0;width: 80px;background-color: #F0FAF5"><input class="center"/></td>
                                <td class="center">${InpBillDetail.amount}</td>
                                <td class="center">${InpBillDetail.itemPrice}</td>
                                <td class="center">${InpBillDetail.amount * InpBillDetail.itemPrice}</td>
                                <td class="center">${InpBillDetail.amount * InpBillDetail.itemPrice}</td>
                                <td>${fns:getDeptName(InpBillDetail.orderDept, "")}</td>
                                <td>${fns:getUserName(InpBillDetail.orderDoctor)}</td>
                                <td>${fns:getDeptName(InpBillDetail.performDept, "")}</td>
                                <td>${fns:getUserName(InpBillDetail.performPerson)}</td>
                                <td><fmt:formatDate value="${InpBillDetail.createDate}" pattern="yyyy-MM-dd HH:mm:ss" /> </td>

                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>
    </div>
</div>

<script>
    ('${type}' == '1' || '${type}' == '2') && $('.returnNum,#returnFee').css('display','none');
    $('#type').val('${type}').trigger('change')
    $(function() {
        $('#returnFee').click(function() {
            var trs = $('#contentTable tbody tr')
            var d = []
            for(var i = 0; i < trs.length; i++) {
                var v = $('.returnNum input', trs[i]).val()
                if(v && v != '') {
                    var amount = $('.returnNum', trs[i]).data('amount');
                    if(amount - v < 0) {
                        toastr.error('退费数量不能大于项目数量，请检查数据');
                        $('.table-selected').removeClass('table-selected')
                        $(trs[i]).addClass('table-selected')
                        return false;
                    }
                    d.push({
                        inpBillId: $(trs[i]).attr('id'),
                        returnNum: v
                    })
                }
            }
            if(d.length == 0) {
                toastr.info('请填写项目的退费数量');
                return false;
            }
            $.ajax({
                contentType: "application/json",
                type: 'post', // 提交方式 get/post
                url: '${ctx}/nurse/nurseReturnFeeApply/saveReturnFee', // 需要提交的 url
                data: JSON.stringify(d),
                dataType: 'json',
                success: function (data) {
                    data && data.code == 'success' ? (toastr.success("保存成功"),$('#searchForm').submit()) : toastr.success("保存失败")
                },
                error: function () {
                    toastr.error('网络连接错误,请检查网络');
                }
            })
        })
    })
</script>


